<?php

namespace Ll\DcatConfig\Models;

use Illuminate\Database\Eloquent\Model;

class LlConfig extends Model
{
    protected $table = 'llconfig';
    public function setValueAttribute($value = null)
    {
        $this->attributes['value'] = is_null($value) ? '' : $value;
    }

    public function getValueTextAttribute($value)
    {
        if ($this->isJson($value)) {
            return json_decode($value, true);
        } else {
            return $value;
        }
    }

    function isJson($string)
    {
        $json = json_decode($string);
        return (json_last_error() == JSON_ERROR_NONE) && (!is_null($json));
    }
}
